The pop( ) Function is used to remove an element from the List.
x = ["Mohan", "Kriti", "Salim"] x.pop(2) print(x)
So, in the above code we have created a 'List' and initialised to the variable 'x'.
Below is how the values are positioned in the List,
Next, we have used the 'pop( )' function that searches for the index/position '2' and removes it from the List.
And as we can see, there is 'Salim' at index/position '2'. So 'Salim' is removed from the List.
And we get the below output,
The 'pop( )' Function can be used to remove an item from the end of the List. If no index is specified at the parameter of 'pop(( )' Function then it removes the last element by default.
x = ["Mohan", "Kriti", "Salim"] x.pop() print(x)
So, in the above code we have created a 'List' and initialised to the variable 'x'.
Below is how the values are positioned in the List,
Next, we have used the 'pop( )' function that searches for the lat value by default(As no index is specified) and removes it from the List.
And as we can see, there is 'Salim' at the end of the List. So 'Salim' is removed from the List.
And we get the below output,